package com.prototype.demo.practice;

import java.io.*;

/**
 * Created by Administrator on 2017/6/9.
 */
public class DeepCustomer implements Serializable{

    private Address address;

    public void setAddress(Address address){
        this.address = address;
    }

    public Address getAddress(){
        return this.address;
    }

    public DeepCustomer clone(){
        try{
            //将对象写入流中
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bao);
            oos.writeObject(this);

            //将对象从流中读取出来
            ByteArrayInputStream bis = new ByteArrayInputStream(bao.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            return (DeepCustomer)ois.readObject();

        }catch(Exception e){
            System.out.println("不支持克隆");
            return null;
        }
    }
}
